//
//  TenderTabbarController.swift
//  Slaughter
//
//  Created by Zhouweibin on 2018/1/21.
//  Copyright © 2018年 zwb. All rights reserved.
//

import UIKit

class ZyaTenderTabbarVC: UITabBarController,UITabBarControllerDelegate,UISearchBarDelegate {
    
    
    var vc_first:ZyaTenderListVC!
    var vc_third:ZyaMyTenderVC!
    var vc_third_jp:ZyaMyTenderJPVC!

    var listType:TBandJPType!
 
 
    init(listType:TBandJPType) {
          self.listType = listType
          super.init(nibName: nil, bundle: nil)
       }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
//        self.setSearchBar()
        self.title = self.listType == .TB ? "采购报价" : "销售报价"
        vc_first = ZyaTenderListVC(listType:self.listType,titleStr: self.listType == .TB ? .zbListKHW : .jpListKHW)
        self.addChild(childVC: vc_first, childTitle: self.listType == .TB ? "采购" : "销售", imageName: "zhaobiaofangan1", selectedImageName: "zhaobiaofangan2")
      
        
        if self.listType == .TB {
            vc_third = (UIStoryboard(name: "ztb", bundle: Bundle.main).instantiateViewController(withIdentifier: "ZyaMyTenderVC") as! ZyaMyTenderVC)
            self.addChild(childVC: vc_third, childTitle: "我的", imageName: "wode1", selectedImageName: "wode2")
        } else {
            vc_third_jp = (UIStoryboard(name: "ztb", bundle: Bundle.main).instantiateViewController(withIdentifier: "ZyaMyTenderJPVC") as! ZyaMyTenderJPVC)
             self.addChild(childVC: vc_third_jp, childTitle: "我的", imageName: "wode1", selectedImageName: "wode2")
        }
        
        
      
        
        
        self.delegate = self
        self.tabBar.tintColor = Theme.primaryColor()
        
        
        for vc in self.viewControllers! {
            if vc.isKind(of: ZyaTenderListVC.self) {
                self.vc_first = vc as? ZyaTenderListVC
                break
            }
        }
    }
    
    private func addChild(childVC: UIViewController, childTitle: String, imageName: String, selectedImageName:String) {
        childVC.title = childTitle
        childVC.tabBarItem.tag = 1
        childVC.tabBarItem.image = UIImage(named: imageName)
        childVC.tabBarItem.selectedImage = UIImage(named: selectedImageName)?.withRenderingMode(.alwaysOriginal)
        self.addChild(childVC)
    }
    
 
    

}
